#include <iostream>
#include <cstdio>
#include <cstring>
#include "minqueue.h"
#include "charcnt.h"
#include "hufftree.h"
#include "decoder.h"

using namespace std;

int main (int argc, char** argv) {
	CharCnt counter;
	map<char, int> cnum;
	
	/* read the input data, store char count in 'cnum' */
	if (argc>1 && !strcmp(argv[1], "-f")) {
		counter.fromFile(argv[2], cnum, 1);
	} else if (!strcmp(argv[1], "-s")){
		counter.fromCin(cnum);
	}
	
	/* build up the Huffman Tree */
	Hufftree ht(cnum);
	ht.checkcode();
	ht.encode(argv[2]); /* the output is writen in code.txt */
	
	Decoder dcr("code.bin");
	dcr.decode("code.bin");
	return 0;
}
